package com.ruoyi.lxzx.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lxzx.mapper.ActivityApplyMapper;
import com.ruoyi.lxzx.domain.ActivityApply;
import com.ruoyi.lxzx.service.IActivityApplyService;

/**
 * 活动报名Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-26
 */
@Service
public class ActivityApplyServiceImpl implements IActivityApplyService 
{
    @Autowired
    private ActivityApplyMapper activityApplyMapper;

    /**
     * 查询活动报名
     * 
     * @param id 活动报名主键
     * @return 活动报名
     */
    @Override
    public ActivityApply selectActivityApplyById(Long id)
    {
        return activityApplyMapper.selectActivityApplyById(id);
    }

    /**
     * 查询活动报名列表
     * 
     * @param activityApply 活动报名
     * @return 活动报名
     */
    @Override
    public List<ActivityApply> selectActivityApplyList(ActivityApply activityApply)
    {
        return activityApplyMapper.selectActivityApplyList(activityApply);
    }

    /**
     * 新增活动报名
     * 
     * @param activityApply 活动报名
     * @return 结果
     */
    @Override
    public int insertActivityApply(ActivityApply activityApply)
    {
        activityApply.setCreateTime(DateUtils.getNowDate());
        return activityApplyMapper.insertActivityApply(activityApply);
    }

    /**
     * 修改活动报名
     * 
     * @param activityApply 活动报名
     * @return 结果
     */
    @Override
    public int updateActivityApply(ActivityApply activityApply)
    {
        activityApply.setUpdateTime(DateUtils.getNowDate());
        return activityApplyMapper.updateActivityApply(activityApply);
    }

    /**
     * 批量删除活动报名
     * 
     * @param ids 需要删除的活动报名主键
     * @return 结果
     */
    @Override
    public int deleteActivityApplyByIds(Long[] ids)
    {
        return activityApplyMapper.deleteActivityApplyByIds(ids);
    }

    /**
     * 删除活动报名信息
     * 
     * @param id 活动报名主键
     * @return 结果
     */
    @Override
    public int deleteActivityApplyById(Long id)
    {
        return activityApplyMapper.deleteActivityApplyById(id);
    }

    @Override
    public void hdbm(Long activityId, Long userId) {
        Long finalUserId = 0L;
        try {
            finalUserId = SecurityUtils.getUserId();
        } catch (Exception e) {
            throw new ServiceException("当前未登录,或登录已过期");
        }
        ActivityApply entity = new ActivityApply();
        entity.setActivityId(activityId);
        entity.setUserId(userId);
        entity.setCreateBy(finalUserId+"");
        entity.setCreateTime(new Date());
        this.insertActivityApply(entity);
    }

    @Override
    public void hdqxbm(Long activityId, Long userId) {
        Long finalUserId = 0L;
        try {
            finalUserId = SecurityUtils.getUserId();
        } catch (Exception e) {
            throw new ServiceException("当前未登录,或登录已过期");
        }
        activityApplyMapper.hdqxbm(activityId,userId);
    }
}
